package com.dubbo.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringBeanContainer {
    private ApplicationContext applicationContext;

    private SpringBeanContainer(String configPath) {
        this.applicationContext = new ClassPathXmlApplicationContext("classpath*:" + configPath);
    }

    public static SpringBeanContainer create(String configPath) {
        return new SpringBeanContainer(configPath);
    }

    @SuppressWarnings("all")
    public <V> V getBean(String beanName) {
        return (V) applicationContext.getBean(beanName);
    }

    public <V> V getBean(Class<V> type) {
        return (applicationContext.getBean(type));
    }
}
